package com.ruoyi.web.controller.production.pesticide;

import java.util.List;

import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.enums.InjectType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.production.domain.pesticide.PesticideAmount;
import com.ruoyi.production.service.pesticide.IPesticideAmountService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 农药量Controller
 *
 * @author ruoyi
 * @date 2021-07-12
 */
@RestController
@RequestMapping("/production/pesticideAmount")
public class PesticideAmountController extends BaseController
{
    @Autowired
    private IPesticideAmountService pesticideAmountService;

    /**
     * 查询农药量列表
     */
    @PreAuthorize("@ss.hasPermi('production:pesticideAmount:list')")
    @GetMapping("/list")
    public TableDataInfo list(PesticideAmount pesticideAmount)
    {
        startPage();
        List<PesticideAmount> list = pesticideAmountService.selectPesticideAmountList(pesticideAmount);
        return getDataTable(list);
    }

    /**
     * 导出农药量列表
     */
    @PreAuthorize("@ss.hasPermi('production:pesticideAmount:export')")
    @Log(title = "农药量", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PesticideAmount pesticideAmount)
    {
        List<PesticideAmount> list = pesticideAmountService.selectPesticideAmountList(pesticideAmount);
        ExcelUtil<PesticideAmount> util = new ExcelUtil<PesticideAmount>(PesticideAmount.class);
        return util.exportExcel(list, "农药量数据");
    }

    /**
     * 获取农药量详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:pesticideAmount:query')")
    @GetMapping(value = "/{pesticideAmountId}")
    public AjaxResult getInfo(@PathVariable("pesticideAmountId") Long pesticideAmountId)
    {
        return AjaxResult.success(pesticideAmountService.selectPesticideAmountById(pesticideAmountId));
    }

    /**
     * 新增农药量
     */
    @PreAuthorize("@ss.hasPermi('production:pesticideAmount:add')")
    @Log(title = "农药量", businessType = BusinessType.INSERT)
    @PostMapping
    @PropertyInject(type = InjectType.Insert)
    public AjaxResult add(@RequestBody PesticideAmount pesticideAmount)
    {
        return toAjax(pesticideAmountService.insertPesticideAmount(pesticideAmount));
    }

    /**
     * 修改农药量
     */
    @PreAuthorize("@ss.hasPermi('production:pesticideAmount:edit')")
    @Log(title = "农药量", businessType = BusinessType.UPDATE)
    @PutMapping
    @PropertyInject(type = InjectType.Update)
    public AjaxResult edit(@RequestBody PesticideAmount pesticideAmount)
    {
        return toAjax(pesticideAmountService.updatePesticideAmount(pesticideAmount));
    }

    /**
     * 删除农药量
     */
    @PreAuthorize("@ss.hasPermi('production:pesticideAmount:remove')")
    @Log(title = "农药量", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pesticideAmountIds}")
    public AjaxResult remove(@PathVariable Long[] pesticideAmountIds)
    {
        return toAjax(pesticideAmountService.deletePesticideAmountByIds(pesticideAmountIds));
    }
}
